package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.UserDto;
import com.zzyl.service.UserService;
import com.zzyl.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
@Api(tags = "用户模块")
public class UserController {
    @Autowired
    private UserService userService;

    //用户分页
    @PostMapping("/page/{pageNum}/{pageSize}")
    @ApiOperation(value = "用户分页")
    public ResponseResult<PageResponse<UserVo>> userpage(@RequestBody UserDto userDto, @PathVariable Integer pageNum,@PathVariable Integer pageSize){
    PageResponse<UserVo> pageResponse =  userService.userpage(userDto,pageNum,pageSize);
    return ResponseResult.success(pageResponse);
    }

    //用户添加
    @PutMapping
    @ApiOperation(value = "用户添加")
    public ResponseResult add(@RequestBody UserDto userDto){
        userService.add(userDto);
        return ResponseResult.success(true);
    }
    //用户修改
    @PatchMapping
    @ApiOperation(value = "用户修改")
    public ResponseResult update(@RequestBody UserDto userDto){
    Boolean b=    userService.update(userDto);
        return ResponseResult.success(b);
    }

    //启用或禁用用户
    @PutMapping("/is-enable/{id}/{status}")
    @ApiOperation(value = "启用或禁用用户")
    public ResponseResult start(@PathVariable Long id,@PathVariable String status){
        userService.start(id,status);
        return ResponseResult.success();
    }

    //用户列表
    @PostMapping("/list")
    @ApiOperation("用户列表")
    public ResponseResult<List<UserVo>> list(@RequestBody UserDto userDto){
    List<UserVo> userVoList  =  userService.list(userDto);
    return ResponseResult.success(userVoList);
    }
    //删除用户
    @DeleteMapping("/remove/{userId}")
    @ApiOperation(value = "删除用户")
    public ResponseResult delete(@PathVariable String userId){

        return ResponseResult.success(userService.delete(userId));
    }

    //重置密码
    @PostMapping("/reset-passwords/{userId}")
    @ApiOperation(value = "密码重置")
    public ResponseResult resetPwd(@PathVariable String userId){
        userService.resetPwd(userId);
        return ResponseResult.success();
    }

}
